package com.gta.edu.sdk.base.call.callback;

import java.util.Date;
import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.logging.LogLevel;
import org.springframework.stereotype.Component;

import com.gta.edu.sdk.base.call.IUserAuthServerCall;
import com.gta.edu.sdk.common.dto.LogInfo;
import com.gta.edu.sdk.common.dto.LogType;
import com.gta.edu.sdk.common.dto.ResultData;
import com.gta.edu.sdk.config.DateJsonValueProcessor;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
@Component
public class UserAuthServerCallBack implements IUserAuthServerCall{

	private static final Logger LOG = LogManager.getLogger(UserAuthServerCallBack.class);

	@Override
	public String getLoginUser(String token) {
		ResultData data = new ResultData();
		LogInfo logInfo = new LogInfo();
		String logId = UUID.randomUUID().toString();
		logInfo.setId(logId);
		logInfo.setDip("user-auth-server");
		logInfo.setDip_service("/user-auth-server/user/getLoginUser");
		logInfo.setLogType(LogType.receive.toString());
		logInfo.setTime(new Date());
		JsonConfig cfg = new JsonConfig();
		cfg.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor());
		logInfo.setLevel(LogLevel.ERROR.toString());
		logInfo.setLogMessage("获取登录用户数据，调用接口失败！");
		LOG.error(JSONObject.fromObject(logInfo, cfg).toString());
		data.setSuccess(false);
		data.setErrorMsg("获取登录用户数据，调用接口失败！");
		return JSONObject.fromObject(data).toString();
	}

}
